/*
 * @描述: 
 * @创建者: kilomChou
 * @Date: 2021-04-11 23:43:12
 * @最后编辑: kilomChou
 * @LastEditTime: 2021-05-15 10:49:48
 */

import { _decorator, Component, Node, Sprite, SpriteFrame } from 'cc';
import { Proto } from '../../common/data/Proto';
import { Conn } from '../net/Conn';
const { ccclass, property } = _decorator;

@ccclass('UISprint')
export class UISprint extends Component {

    /** 是否控制状态 */
    isCtrled = false;
    /** 上一次发送协议的时间 */
    lastSend = 0

    @property(SpriteFrame)
    imgNormal: SpriteFrame
    @property(SpriteFrame)
    imgActed: SpriteFrame

    start() {
        this.node.on(Node.EventType.TOUCH_START, () => {
            this.getComponent(Sprite).spriteFrame = this.imgActed;
            Conn.send(Proto.C2S_CTRL_SPRINT, { isSprint: true });
        }, this)
        this.node.on(Node.EventType.TOUCH_END, () => {
            this.getComponent(Sprite).spriteFrame = this.imgNormal;
            Conn.send(Proto.C2S_CTRL_SPRINT, { isSprint: false });
        }, this)
    }
}
